<div class="layui-fluid nepadmin-pad0 nepadmin-mar0 list0 pay_set" id="list" lay-title="网卡管理">
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
			<div class="layui-form layui-card-header hxradmin-card-header">
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">关键词查询</label>
						<div class="layui-input-inline">
							<input type="text" name="user" placeholder="产品key或产品秘钥" class="layui-input" autocomplete="off">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">分配状态</label>
						<div class="layui-input-inline">
							<div class="layui-unselect layui-form-select">
								<div class="layui-select-title"><input name="status" type="text" value="" readonly class="layui-input layui-unselect"><i
									 class="layui-edge"></i></div>
								<dl class="layui-anim layui-anim-upbit" style="">
									<dd lay-value="" class="layui-select-tips layui-this">选择状态</dd>
									<dd data='1'>已分配</dd>
									<dd data='2'>未分配</dd>
								</dl>
							</div>
						</div>
					</div>
					<div class="layui-inline">
						<button class="layui-btn" data-type="reload" id="search">搜索</button>
					</div>
					<div class="layui-inline">
						<button class="layui-btn" data-type="excel" id="pexcel">导出数据</button>
					</div>
				</div>
			</div>
          <div class="layui-card-body">
			<div>
				<button class="layui-btn layuiadmin-btn-list" data-type="batchdel">删除</button>
				<button class="layui-btn layuiadmin-btn-list" data-type="add">添加</button>
			</div>
            <table class="layui-hide" id="list-table" lay-filter="list-table"></table>
			<script type="text/html" id="list-tableF">
			  {{#if(d.status==1){}}
				<span class="layui-badge layui-bg-green">已分配</span>
			  {{#}else{}}
				<span class="layui-badge">未分配</span>
			  {{#}}}
			</script>
			<div id="list-toolbar" style="display: none;">
				
			  <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
			            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
			</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<script>
   //表格数据渲染
  var formurl='device/networkform',formarea=['500px', '400px'];
  layui.use(['table','form'], function () {
	  var table = layui.table
	  ,form = layui.form
	  ,$ = layui.$;
	  layui.admin.initlist(table,'network/card_list',275,[[
		{type:'checkbox',fixed:'left'}
        ,{field:'product_key', title: '产品key', minWidth:100}
		,{field:'device_name_key', title: '产品秘钥', minWidth:200}
		,{field:'device_sn', title: '已分配设备编号', minWidth:200}
		,{field:'status', title:'分配状态', width:100, templet: '#list-tableF'}
		,{field:'create_time', title: '创建时间', width:200}
		,{title:'操作', toolbar: '#list-toolbar',fixed:'right', width:150}
      ]])
	//监听表格操作事件
	table.on('tool(list-table)', function(obj){
	  var data = obj.data;
	  //删除
	  if(obj.event === 'del'){
		layer.confirm('确定删除'+data.product_key+'?', function(index){
		  layui.admin.delF(table,'network/card_delete',{network_card_id:data.network_card_id});
		});
	  } else if(obj.event === 'edit'){//编辑
		layui.admin.pupF('编辑网卡',formarea,formurl,2,data)
	  }
	});
	var active = {
	  //多行删除
	  batchdel:function(){
		  layui.admin.delsF(table,'network/card_delete','network_card_id')
	  }
	  //添加
	  ,add: function(othis){
		layui.admin.pupF('添加网卡',formarea,formurl,1,{})
	  }
	}; 
	//操作dom
	$('.layui-btn.layuiadmin-btn-list').on('click', function(){
	  var type = $(this).data('type');
	  active[type] ? active[type].call(this) : '';
	});
	//搜索
	$('#search').on('click', function() {
		var obj=$(this).parents('.layui-form-item');
		var val1 = obj.find('input[name="user"]').val(),
		val2 = obj.find('input[name="status"]').attr('data')
		layui.admin.reloads({
			search_text:val1,
			status:val2
		});
	});
	  //导出
	  $('#pexcel').on('click', function() {
		  var obj=$(this).parents('.layui-form-item');
		  var val1 = obj.find('input[name="user"]').val(),
				  val2 = obj.find('input[name="status"]').attr('data')
		  layui.admin.excel(table,'network/card_list',
				  {
					  search_text:val1,
					  status:val2
				  },'');
	  });
  });
</script>